import { followHolidays } from '../holidays'
import { getYmd, lunar } from '../../../../components/modules/calendar/index'
import { daystamp, today} from './today'

// 最近带假期节日的数据
export function theRecentVaction(){
  const nextVacations = []
  const prevVacations = []
  let   rightVaction = null

  followHolidays.forEach((item, ii)=>{
    const [date, name, count] = item
    const tmpDate = getYmd(date)
    tmpDate.name = name
    tmpDate.count = count
    if (tmpDate.timestamp > today.timestamp) {
      nextVacations.push(tmpDate)
    } else {
      prevVacations.push(tmpDate)
    }
  })
  
  const nextVacation = nextVacations[0]
  const prevVacation = prevVacations[prevVacations.length - 1]
  const gap = (nextVacation.timestamp - today.timestamp) / daystamp
  const preGap = (today.timestamp - prevVacation.timestamp) / daystamp
  if (preGap <= (prevVacation.count-1) || preGap === 0) {
    rightVaction = prevVacation
    rightVaction.gap = 0  
  } else {
    rightVaction = nextVacation
    rightVaction.gap = gap  // 距离下一个节日还有多少天
  }

  return rightVaction
}